<?php

// nc_del.php
// Michael Baker
// 2010.07.12
//
// Drop a nodecouple (complain if it belongs to a workflow)

session_start();

define("IN_MDM", true);
define("CUR_PAGE_TITLE", "Delete segment");
define("CUR_FLAG", "nc.del");

include '../includes/all.php';
include 'inc/header.php';

$id = $_GET[ "id" ];

if ( $_GET["confirm"] )
{
  $c = count($dbase->search_for_workflows($id));
  $wf = ($c == 1) ? "workflow" : "workflows";
  
  if ( count($dbase->search_for_workflows( $id )) )
  {
    $_SESSION[ "MESSAGE" ] = array( 1, "Unable to drop segment $id: segment is a dependency of $c $wf and therefore cannot be removed" );    
    header( "Location: " . $_SESSION[ "from" ] );
  }
  else 
  {
    $dbase->delete_nodecouple( $id );
    $_SESSION[ "MESSAGE" ] = array( 0, "Segment $id removed" );  
    header( "Location: " . $_SESSION[ "from" ] );
  }
}
else 
{
  $_SESSION[ "to" ] = "nc_del.php?id=$id&confirm=1";
  $_SESSION[ "confirm_msg" ] = "Are you sure you wish to delete this segment?";
  header( "Location: confirm.php" );
}

?>